//
//  ActivityDetailCommentView.m
//  Lmm_IOS
//
//  Created by 张哲炜 on 2018/9/26.
//  Copyright © 2018年 lmm. All rights reserved.
//

#import "ActivityDetailCommentView.h"

@implementation ActivityDetailCommentView{
    
    UIView * superView;
    UITableView *tableView;
    UIRefreshControl *refreshControl;
    ActivityModel *activityModel;
    
    NSMutableArray *data;
    
    int page;
    
}

- (id)initWithFrame:(CGRect)frame :(UIView *) superView {
    
    self->superView = superView;
    
    self = [super initWithFrame:frame];
    
    if (self) {
   
        [self drawView];
        
    }
    return self;
}


- (void) initView:(ActivityModel *)activityModel {

    self->activityModel = activityModel;
   

    [self->tableView reloadData];

}

- (void) drawView {
    
   
    self->tableView = UITableView.new;
    self->tableView.backgroundColor = [UIColor clearColor];
    self->tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self->tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self->tableView.dataSource = self;
    self->tableView.delegate = self;
    [self addSubview:self->tableView];
    
    [self->tableView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.top);
        make.left.equalTo(self.left);
        make.right.equalTo(self.right);
        make.bottom.equalTo(self.bottom).offset(-89);
    }];
    
    UIView *divideLine = UIView.new;
    divideLine.backgroundColor =UIColorFromRGB(0xCCCCCC) ;
    [self addSubview:divideLine];
    
    [divideLine makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->tableView.bottom);
        make.left.equalTo(self.left);
        make.right.equalTo(self.right);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);
    }];
    
    UIView *commentView = UIView.new;
    [self addSubview:commentView];
    
    [commentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(divideLine.bottom);
        make.left.equalTo(self.left);
        make.right.equalTo(self.right);
        make.bottom.equalTo(self.bottom).offset(-40);
    }];
    
    commentView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showCommentView)];
    [commentView addGestureRecognizer:tapGestureRecognizer];
    
    UILabel *commentLabelRight = UILabel.new;
    commentLabelRight.font = [UIFont fontWithName:MAIN_FONT_NAME size:16];
    commentLabelRight.textColor = SECOND_FONT_COLOR;
    commentLabelRight.numberOfLines = 1;
    commentLabelRight.text = @"发表评论";
    [commentView addSubview:commentLabelRight];
    
    [commentLabelRight makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(commentView.top).offset(0);
        make.right.equalTo(self.right).offset(-10);
        make.bottom.equalTo(commentView.bottom);
    }];
    
    UILabel *commentLabelLeft = UILabel.new;
    commentLabelLeft.backgroundColor = BG_COLOR;
    commentLabelLeft.font = [UIFont fontWithName:MAIN_FONT_NAME size:16];
    commentLabelLeft.textColor = UIColorFromRGB(0xCCCCCC);
    commentLabelLeft.numberOfLines = 1;
    commentLabelLeft.text = @" 我来说两句...";
    [commentView addSubview:commentLabelLeft];
    
    [commentLabelLeft makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(commentView.top).offset(8);
        make.left.equalTo(self.left).offset(10);
        make.right.equalTo(commentLabelRight.left).offset(-10);
        make.bottom.equalTo(commentView.bottom).offset(-8);
    }];
    
    
    
}


- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier =@"CommentTableViewCell";
    CommentTableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // 如果取出的表格行为nil
    if (tableViewCell == nil) {
        //创建一个UITableViewCell对象，并绑定到cellID
        tableViewCell = [[CommentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        [tableViewCell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
   
    CommentModel * commentModel = [activityModel.comments objectAtIndex:indexPath.row];
    [tableViewCell setComment:commentModel];
   // [self->tableView reloadData];
    
    return tableViewCell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [activityModel.comments count];
}



//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//    return 200 ;
//
//}

//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//
//    if(scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
//
//        //[self getCommentList];
//    }
//}


- (void) showCommentView {
    
    
    
}




@end
